package com.discuz.spider;

import java.util.List;
import java.util.Set;



import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebClientOptions;
import com.gargoylesoftware.htmlunit.util.Cookie;

public class WebClientAgent {

	
	private static WebClient client ;
	
	public static WebClient get(){
		if(client == null){
			client	= new WebClient(BrowserVersion.CHROME);
			WebClientOptions opts = client.getOptions();
			//client.getCookieManager().setCookiesEnabled(true);
			opts.setCssEnabled(false);
			opts.setJavaScriptEnabled(false);
			opts.setThrowExceptionOnScriptError(false);
			//opts.setTimeout(10*1000);
		}
		return client;
	}
	
	
	public static String checkCookie() {

		Set<Cookie> cookies = client.getCookieManager().getCookies();
		String tmpcookies = "";
		for (Cookie c : cookies) {
			tmpcookies += (c.getName() + "=" + c.getValue());
			tmpcookies += ";";
		}
		
		return tmpcookies;
	}
	
	
	
	
}
